﻿using Abp;
using Abp.Dependency;
using Abp.Notifications;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace FwProject.ManagerNotification
{
    /// <summary>
    /// 订阅通知
    /// </summary>
    public class SubscribeToNotifications : ITransientDependency
    {
        private readonly INotificationSubscriptionManager _notificationSubscriptionManager;
        public SubscribeToNotifications(INotificationSubscriptionManager notificationSubscriptionManager)
        {
            _notificationSubscriptionManager = notificationSubscriptionManager;
        }

        #region 订单通知
        /// <summary>
        /// 订阅订单通知
        /// </summary>
        /// <param name="tenantId">租户Id</param>
        /// <param name="userId">订阅人Id</param>
        /// <returns></returns>
        public async Task Subscribe_OrderNotification(int? tenantId, long userId)
        {
            await _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(tenantId, userId), NotificationTypeHelp.ORDERNOTIFICATION);
        }

        /// <summary>
        /// 判断是否订阅订单通知
        /// </summary>
        /// <param name="tenantId">租户Id</param>
        /// <param name="userId">订阅人Id</param>
        /// <returns></returns>
        public async Task<bool> IsSubscribed_OrderNotification(int? tenantId, long userId)
        {
            var boo = await _notificationSubscriptionManager.IsSubscribedAsync(new UserIdentifier(tenantId, userId), NotificationTypeHelp.ORDERNOTIFICATION);
            return boo;
        }

        /// <summary>
        /// 退订订单通知
        /// </summary>
        /// <param name="tenantId">租户Id</param>
        /// <param name="userId">订阅人Id</param>
        /// <returns></returns>
        public async Task Unsubscribe_OrderNotification(int? tenantId, long userId)
        {
            await _notificationSubscriptionManager.UnsubscribeAsync(new UserIdentifier(tenantId, userId), NotificationTypeHelp.ORDERNOTIFICATION);
        }
        #endregion

    }
}
